﻿using System;
using System.Collections.Generic;
using XStudio.XCRF.Data.Enums;
using XStudio.XCRF.Resources.Enums;
using System.Web.Mvc;

namespace XStudio.XCRF.Web.Models.Enums
{
    /// <summary>
    /// 成员类型信息
    /// </summary>
    public class MemberTypeInfo
    {
        /// <summary>
        /// 成员类型名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 对应键值
        /// </summary>
        public byte Value { get; set; }

        public static string GetName(byte type)
        {
            string key = ((MemberTypes)type).ToString();
            return MemberTypeResource.ResourceManager.GetString(key);
        }

        /// <summary>
        /// 获取成员类型信息集合
        /// </summary>
        public static List<MemberTypeInfo> MemberTypeInfoes
        {
            get
            {
                List<MemberTypeInfo> infoes = new List<MemberTypeInfo>();
                string[] typeNames = Enum.GetNames(typeof(MemberTypes));
                foreach (string typeName in typeNames)
                {
                    MemberTypes type = (MemberTypes)Enum.Parse(typeof(MemberTypes), typeName);
                    string name = MemberTypeResource.ResourceManager.GetString(typeName);
                    infoes.Add(new MemberTypeInfo
                    {
                        Name = name,
                        Value = (byte)type
                    });
                }
                return infoes;
            }
        }

        public static IEnumerable<SelectListItem> SelectListItems
        {
            get
            {
                List<SelectListItem> items = new List<SelectListItem>();
                string[] typeNames = Enum.GetNames(typeof(MemberTypes));
                foreach (string typeName in typeNames)
                {
                    MemberTypes type = (MemberTypes)Enum.Parse(typeof(MemberTypes), typeName);
                    string name = MemberTypeResource.ResourceManager.GetString(typeName);
                    items.Add(new SelectListItem
                    {
                        Text = name,
                        Value = ((byte)type).ToString()
                    });
                }
                return items;
            }
        }
    }
}